//axios请求封装
import { useSystemStore } from '@/store/modules/system'
import { ElMessage } from 'element-plus'

const baseURL = 'http://47.113.185.182:7374'
const request = (config) => {
  //url拼接
  config.url = baseURL + config.url
  //token
  const $systemStore = useSystemStore()
  const token = $systemStore.token
  if (token) {
    config.headers['Authorization'] = 'Bearer ' + token
  }
  return new Promise((resolve, reject) => {
    window.api.requestProxy(config).then((res) => {
      console.log('返回信息', res)
      if (res.success) {
        switch (res.code) {
          case 200:
            ElMessage.success(res.msg)
            break
          case 401:
            ElMessage.error(res.msg)
            //跳转登录
            break
          default:
            ElMessage.error(res.msg)
        }
        resolve(res.data)
      } else {
        if (res.code == 401) {
          //跳转登录
        }
        ElMessage.error(res.msg)
        reject(res.msg)
      }
    })
  })
}

export default request
